<template>
  <div id="myBuyHistory">
  <!--<x-header title="我的消费记录" style="position:fixed;top:0px;z-index:1000;width:100%" :right-options="{showMore: true}" @on-click-more="show = true"></x-header> -->
  <x-header>
    <span>我的消费记录</span>
    <x-icon @click="goBackBtn" slot="ios-arrow-left" type="ios-arrow-back" size="35" style="fill:#fff;position:relative;top:-8px;left:-3px;"></x-icon>
    <x-icon @click="hengshuBtn" v-if="isHeng" slot="right" type="android-menu" size="35" style="fill:#fff;position:relative;top:-8px;left:-3px;"></x-icon>
    <x-icon @click="hengshuBtn" v-if="!isHeng" slot="right" type="android-apps" size="35" style="fill:#fff;position:relative;top:-8px;left:-3px;"></x-icon>
  </x-header>

                <!-- <share-page :shareList="shareList"></share-page> -->
                    <div id="shareList_wrap" v-if="hasRecord"> 
                      <div class="shareList_contents" v-for="(item,index) in shareList" :key="index" >
                          <div class="shareList_img" @click="shopListDetail(item.goodsid)">
                              <img :src="item.src" alt="">
                          </div>
                          <div class="shareList_detail">
                            <div class="shareList_desc">{{item.title}},{{item.desc}}</div>
                            <div class="shareList_spans"><span>{{item.keyWorlds}}</span></div>
                            <div class="shareList_prices">￥{{item.shop_price}} <span>{{item.rebate}}</span></div>
                            <div class="shareList_others"> 20条评价 &nbsp;98%好评</div>
                            <div class="deleData" @click="detele(item.buyid)">删除记录</div>
                              <toast position="middle" v-model="messShow" type="text">{{message}}</toast>
                            
                          </div>
                      </div>
                  </div>
                   <div class="cart_wrap" v-else style="margin-top:46px">
                    <x-button mini plain class="go_choose" @click.native="go_classify">马上去挑选</x-button>
                  </div>

  </div>
</template>

<style>
#myBuyHistory .box{
  /* height: 10.625rem; */
  background: white;
  margin-top: .3125rem;
  padding: 0rem .625rem;
}
#myBuyHistory .shou_wraps{
  padding-top: 10px;
  display: flex;
  padding-bottom:10px
  
}
#myBuyHistory .shou_item1{
  width:100px 
}
#myBuyHistory .shou_item1 img{
 height: 4.75rem;
  width: 90px
}
#myBuyHistory .shou_item2{
  flex: 2
}
#myBuyHistory .shou_item3{
  width: 100px;
  text-align: right;

}
 #myBuyHistory .title_div{
  height: 2.875rem;
  line-height: 2.875rem;
  color: #909291;
  border-bottom:1px solid #e7e7e7; 
} 
#myBuyHistory .shou_item3 .left_div_bottom1{
  font-size:0.8rem; 
  /* border: 1px solid red; */
  margin-top:1.25rem;
  padding: .125rem .3125rem;
  /* color:  red; */
  border-radius:.1875rem;
  float: right;
}
#myBuyHistory .shou_item3 .left_div_bottom1 img{
  width: 15px;
  height: 20px;
}
.cart_wrap {
  background: url(/static/cart/gwbg@2x.png);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  width: 100%;
  height: 43rem;
  position: relative;
}
.go_choose {
  position: absolute;
  top: 30rem;
  left: 10rem;
}
</style>

<script>
import { XHeader, Flexbox, Toast,FlexboxItem, Divider,XButton} from 'vux';
import { homeUrl } from "../../components/utils/utils.js";
import SharePage from "../../components/toolComponent/sharePage";

import axios from "axios";
import qs from "qs";
export default {
  components: {
    XHeader,
    Flexbox,
    FlexboxItem,
    Divider,
    Toast,
    SharePage,
    XButton
  },
  data(){
    return{
      isHeng:false , 
      shareList:[],
      messShow:false,
      message:"",
     wxOpenId:localStorage.getItem("openid"),
     hasRecord:true
    }
  },
  methods:{
    goBackBtn() {
      window.history.go(-1)
    } , 
    hengshuBtn() {
      this.$data.isHeng = !this.$data.isHeng
    } , 
    buyHistory(){
      // alert(this.wxOpenId)
      var datas = qs.stringify({
        wxid:"oCBm3vxlqwJjUbBDshKiQ50IFSjs",
      });
      axios
        .post(homeUrl() + "buyhistorySelect/", datas, { emulateJSON: true })
        .then(
          result => {
            console.log(result);
           if(result.data.status=="ok"){
            //  this.buyList=result.data.data;
              var searchArr=[];
             var shareLists=result.data.data;
             if(shareLists.length=="0"){
                this.hasRecord=false
             }else{
               for(var i=0;i<shareLists.length;i++){
               var searchObj = {};
                searchObj.src =this.urlList(shareLists[i].goods.product_thumb_image);
                  // ;
                searchObj.title = shareLists[i].goods.goodsname;
                searchObj.desc=shareLists[i].goods.standard
               
                searchObj.goodsid = shareLists[i].goods.goodsid;
                searchObj.shop_price=shareLists[i].goods.shop_price;
                searchObj.market_price=shareLists[i].goods.market_price;
                
                searchObj.rebate="返利￥"+shareLists[i].goods.rebate+"元";
                searchObj.kucun=shareLists[i].goods.counts;
                searchObj.sellCount=shareLists[i].goods.sellcount;
                searchObj.buyid=shareLists[i].buyid;  
                // searchObj.deleBtn='<div @click="deleRecord('+shareLists[i].buyid+')">删除记录</div>'              
                searchArr.push(searchObj);

              }
              this.shareList = searchArr;
             }
               
           }
          },
          error => {
            this.$vux.toast.text("网络请求失败....", "bottom");
            console.log(error);
          }
        );
    },
    // 图片
    urlList(imgObj){
      if(imgObj!=null){
          //  var datasSrc=imgObj.split("---");
          var srcUrl=homeUrl()+imgObj;
          console.log(srcUrl)
          return srcUrl
      }
       
    },
    // 去详情
    shopListDetail(goodsid){
      console.log(goodsid)
      this.$router.push({
        name: 'goods_detail',
        params: {
          goodsId: goodsid
        }
      })
    },
    // 取消收藏
    detele(buyId){
      console.log(buyId);
      var datas = qs.stringify({
        buyid:buyId,
      });
      axios
        .post(homeUrl() + "buyhistoryDelete/", datas, { emulateJSON: true })
        .then(
          result => {
            console.log(result);
           if(result.data.status=="ok"){
            this.messShow=true;
            this.message="删除记录";
            this.buyHistory()
            
           }
          },
          error => {
            this.$vux.toast.text("网络请求失败....", "bottom");
            console.log(error);
          }
        );
    },
       //   删除分享记录
    deleData(buyid){

        console.log(buyid);
        // if(buyid!=undefined){
        // var datas = qs.stringify({
        //         buyid:buyid,
        //       });
        //       axios
        //         .post(homeUrl() + "buyhistoryDelete/", datas, { emulateJSON: true })
        //         .then(
        //           result => {
        //             console.log(result);
        //           if(result.data.status=="ok"){
        //             // this.messShow=true;
        //             // this.message="删除成功";
        //             // this.buyHistory()
                    
        //           }
        //           },
        //           error => {
        //             this.$vux.toast.text("网络请求失败....", "bottom");
        //             console.log(error);
        //           }
        //         );
        // }
        // 分享记录删除
        //  if(shareid!=undefined){
        //       var datas = qs.stringify({
        //       shareid:shareid,
        //     });
        //     axios
        //       .post(homeUrl() + "delShare/", datas, { emulateJSON: true })
        //       .then(
        //         result => {
        //           console.log(result);
              
        //         },
        //         error => {
        //           this.$vux.toast.text("网络请求失败....", "bottom");
        //           console.log(error);
        //         }
        //       );
        // }
     
    },
  },
  created(){
    this.buyHistory()
  },
  updated: function() {
    // this.buyHistory()
    
  },
}
</script>